<template>
  <!--启用该模式会在激活导航时候以index作为path进行路由跳转-->
  <el-menu
    :default-active="'/index'"
    router
    mode="horizontal"
    background-color="white"
    text-color="#222"
    active-text-color="red"
    style="min-width: 1300px">
    <el-menu-item v-for="(item,i) in navList" :key="i" :index="item.name">
      {{ item.navItem }}
    </el-menu-item>
    <i class="el-icon-s-home" v-on:click="logout" style="float:right;font-size: 40px;color: #222;padding: 10px"></i>
    <span style="position: absolute;padding-top: 20px;right: 43%;font-size: 20px;font-weight: bold"></span>
  </el-menu>
</template>

<script>
export default {
  name: 'NavMenu',
  data () {
    return {
      navList: [
        {name: '/blogs', navItem: '首页'},
        {name: '/admin', navItem: '管理中心'}
      ]
    }
  },
  methods: {
    logout(){
      var _this = this
      this.$axios.get('/logout').then(resp=>{
        if(resp.data.code===200) {
          _this.$store.commit('logout')
          _this.$router.replace('/login')
        }
      })
    }
  }
}
</script>

<style scoped>
.el-icon-s-home{
  cursor: pointer;
  outline:0;
}
a{
  text-decoration: none;
}

span {
  pointer-events: none;
}
</style>

